package com.yt.product.server.common.interceptor;

import com.yt.product.server.common.interceptor.ApiHandlerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @Description ：extends WebMvcConfigurerAdapter 已经被弃用，直接实现WebMvcConfigurer该接口就行了
 * @Author ： 解风
 * @Date ： 2017/11/28 09:41
 */
@Configuration("productApiWebConfig")
public class ApiWebConfig implements WebMvcConfigurer {


    @Autowired
    private ApiHandlerInterceptor apiHandlerInterceptor;

    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(apiHandlerInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/v2/api-docs", "/images/**","/swagger-resources/**","/static/**", "/api/dispatch/available-employees/**", "/api/rule-config/auto-dispatch/**", "/api/dispatch/workOrder/getProgress"); // 排除拦截;
    }

    @Override
    public void addCorsMappings(CorsRegistry registry){
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT","PATCH")
                .maxAge(3600);
    }

}